/**
 * Copyright (c) 2022 Beijing Jiaotong University
 * PhotLab is licensed under [Open Source License].
 * You can use this software according to the terms and conditions of the [Open Source License].
 * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *
 * See the [Open Source License] for more details.
 *
 * Author: Zhenjie Wei, Qing'ao Zhang
 * Created: Mar. 12, 2023
 * Supported by: National Key Research and Development Program of China
 */

import { reactive, nextTick, getCurrentInstance } from 'vue'
import screenfull from 'screenfull'
import { commandManager } from "@/common/cmd/manager"
import { engineManager } from '@/services/phot_client/engine'
import { graphManager } from '@/services/phot_client/graph'
import { deviceManager } from '@/services/phot_client/device'
import { useStore } from 'vuex'
import { ipcRenderer } from 'electron'
import { deepClone } from '@/utils'
import upath from 'upath'
import { PhotTaskStatus } from '@/common/types/phot_types'
import { engineService as engine, graphService as graph, projectService as project } from '@/services/phot_client/client'
import { mainManager } from '@/services/phot_client/main'
const exec = require('child_process').exec
const useHooks = () => {
    const { proxy } = getCurrentInstance() as any
    const store = useStore()
    const temporaryData = reactive({
        photGrid: {}
    }) as any
    const hooksData = reactive({
        theme: false,
        sysToolbarList: [
            {
                title: '文件',
                type: 'file',
                options: [
                    {
                        display: 'row',
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '新建',
                                icon: 'xinjian',
                                id: '',
                                arrow: true,
                                fn: async () => {
                                    await nextTick()
                                    newGraphClickHandle()
                                    commandManager.executeCommand('graphManager.newGraph')
                                }
                            },
                        ]
                    },
                    {
                        display: 'row',
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '保存',
                                icon: 'baocun',
                                id: '',
                                arrow: true,
                                dataList: [
                                    {
                                        label: '保存文件',
                                        value: 'saveFile',
                                        fn: async () => {
                                            await graphManager.saveGraph()
                                            commandManager.executeCommand('graphManager.saveGraph')
                                        },
                                    },
                                    {
                                        label: '保存项目到本地',
                                        value: 'saveFileAs',
                                        fn: async() => {
                                            proxy.$refs.FolderBrowserDialogRef.init('saveGraphAs')
                                        },
                                    },
                                ]
                            },
                        ]
                    },
                    {
                        display: 'column',
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '打开',
                                icon: 'dakai',
                                id: '',
                                fn: async () => {
                                    await nextTick()
                                    folderBrowserClickHandle('open graph')
                                    commandManager.executeCommand('graphManager.openGraph')
                                }
                            },
                            {
                                display: 'row',
                                label: '关闭',
                                icon: 'folder-close',
                                id: '',
                                fn: async () => {
                                    await graphManager.saveGraph()
                                    await graphManager.closeGraph(graphManager.photGraph.uid, graphManager.photGraph.graphId)
                                    await nextTick()

                                    commandManager.executeCommand('graphManager.closeGraph')
                                }
                            },
                            {
                                display: 'row',
                                label: '退出',
                                icon: 'tuichu',
                                id: '',
                                fn: () => commandManager.executeCommand('file.quit')
                            },
                        ]
                    },
                    {
                        display: 'column',
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '打印',
                                icon: 'dayin',
                                id: '',
                                fn: () => commandManager.executeCommand('main.file.print')
                            },
                            {
                                display: 'row',
                                label: '帮助',
                                icon: 'help',
                                id: '',
                                arrow: true,
                                fn: () => commandManager.executeCommand('main.file.help')
                            },
                            {
                                display: 'row',
                                label: '设置',
                                icon: 'shezhi',
                                id: '',
                                fn: () => {
                                    settingClickHandle()
                                    commandManager.executeCommand('main.file.setting')
                                }
                            },
                        ]
                    },
                ]
            },
            {
                title: '剪切板',
                type: 'clipboard',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '粘贴',
                                icon: 'niantie',
                                id: '',
                                // arrow: true,
                                fn: () => commandManager.executeCommand('main.clipboard.stickup')
                            }
                        ]
                    },
                    {
                        display: 'column',
                        showText: true,
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '复制',
                                icon: 'fuzhi',
                                id: '',
                                fn: () => commandManager.executeCommand('main.clipboard.copy')
                            },
                            {
                                display: 'row',
                                label: '剪切',
                                icon: 'cut',
                                id: '',
                                fn: () => commandManager.executeCommand('main.clipboard.cut')
                            },
                            {
                                display: 'row',
                                label: '删除',
                                icon: 'shanchu',
                                id: '',
                                fn: () => commandManager.executeCommand('main.clipboard.clean')
                            },
                        ]
                    },
                ]
            },
            {
                title: '文本编辑',
                type: 'text-mode',
                options: [
                    {
                        display: 'column',
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '添加文本',
                                icon: 'add-text',
                                id: '7',
                                fn: () => {
                                  console.log('添加文本')
                                }
                            }
                        ]
                    },
                    {
                        display: 'row',
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '字体',
                                icon: '',
                                id: '8-1',
                                fn: () => {
                                  console.log('字体')
                                }
                            },
                            {
                                display: 'row',
                                label: '大小',
                                icon: '',
                                id: '8-2',
                                fn: () => {
                                  console.log('大小')
                                }
                            },
                        ]
                    },
                    {
                        display: 'row',
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '',
                                icon: 'text-left',
                                id: '9-1',
                                fn: () => {
                                  console.log('text-left')
                                }
                            },
                            {
                                display: 'row',
                                label: '',
                                icon: 'text-center',
                                id: '9-2',
                                fn: () => {
                                  console.log('text-center')
                                }
                            },
                            {
                                display: 'row',
                                label: '',
                                icon: 'text-right',
                                id: '9-3',
                                fn: () => {
                                  console.log('text-right')
                                }
                            },
                            {
                                display: 'row',
                                label: '',
                                icon: 'text-background-color',
                                id: '9-4',
                                fn: () => {
                                  console.log('text-background-color')
                                }
                            },
                            {
                                display: 'row',
                                label: '',
                                icon: 'text-color',
                                id: '9-5',
                                fn: () => {
                                  console.log('text-color')
                                }
                            },
                        ]
                    },
                ]
            },
            {
                title: '视图',
                options: [
                    {
                        display: 'column',
                        showText: true,
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '还原',
                                icon: 'restore',
                                id: '',
                                fn: () => commandManager.executeCommand('main.view.restore')
                            },
                            {
                                display: 'row',
                                label: '放大',
                                icon: 'zoom-in',
                                id: '',
                                fn: () => {
                                    console.log(screenfull)
                                    onScreenfullClickHandle()
                                    commandManager.executeCommand('main.view.zoomIn')
                                }
                            },
                        ]
                    },
                    {
                        display: 'column',
                        showText: true,
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '平移',
                                icon: 'translate-45',
                                id: '',
                                fn: () => commandManager.executeCommand('main.view.translate')
                            },
                            {
                                display: 'row',
                                label: '缩小',
                                icon: 'zoom-out',
                                id: '',
                                fn: () => commandManager.executeCommand('main.view.zoomOut')
                            },
                        ]
                    },
                ]
            },
            {
                title: '组件编辑',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '编辑参数',
                                icon: 'a-bianzhicanshu',
                                id: '',
                                fn: async () => {
                                    if (!graphManager.photGraph) {
                                        return proxy.$toast({
                                            type: 'error',
                                            value: '未检测到工程'
                                        })
                                    }
                                    await nextTick()
                                    parameterEditorClickHandle()
                                    commandManager.executeCommand('main.editor.edit')
                                }
                            },
                            {
                                display: 'column',
                                label: '在PhotCode打开',
                                icon: 'a-zaiPhotCodedakai',
                                id: '',
                                fn: () => {
                                    cmdFn('D://code/mlyGitLibrary/phot-client')
                                    commandManager.executeCommand('main.editor.openInCode')
                                }
                            },
                            {
                                display: 'column',
                                label: '启动PhotCode',
                                icon: 'a-qidongPhotCode',
                                id: '',
                                fn: () => {
                                    cmdFn()
                                    commandManager.executeCommand('main.editor.startCode')
                                }
                            },
                        ]
                    },
                ]
            },
            {
                title: '仿真',
                options: [
                    {
                        display: 'column',
                        showText: true,
                        size: 'normal',
                        list: [
                            {
                                display: 'column',
                                label: '运行',
                                icon: 'kaishi',
                                id: '',
                                fn: async () => {
                                    if (!graphManager.photGraph) {
                                        return proxy.$toast({
                                            type: 'error',
                                            value: '未检测到工程'
                                        })
                                    }
                                    proxy.$loading.open('仿真任务创建中...')
                                    const errorLog = await mainManager.getServerLog('1000', 'phot_engine')
                                    console.log(errorLog)
                                    try {
                                        const taskStatus = await engineManager.getTaskStatus(graphManager.photGraph.graphId!)
                                        console.log('taskId: ',engineManager.taskId)
                                        console.log('taskStatus: ',taskStatus)
                                        if (taskStatus === PhotTaskStatus.TASK_RUNNING || taskStatus === PhotTaskStatus.TASK_STOPPED) {
                                            await engineManager.restartTask()
                                            await engineManager.getTaskExceptionInformation()
                                            proxy.$toast({
                                                value: '计算完成',
                                                type: 'success'
                                            })
                                        } else if ((graphManager.photGraph.graphId && !taskStatus) || taskStatus === PhotTaskStatus.TASK_CREATING || taskStatus === PhotTaskStatus.TASK_NO_RESPONDING || taskStatus === PhotTaskStatus.TASK_DIED || taskStatus === PhotTaskStatus.TASK_ACCOMPLISHED) {
                                            proxy.$refs.MessageLogRef.init()
                                            // taskStatus && taskStatus !== 5 ? await engineManager.startTask() : await engineManager.addTask(graphManager.photGraph)
                                            if (!taskStatus || taskStatus === 5) {
                                                await engineManager.createTask(graphManager.photGraph.graphId)
                                            }
                                            taskStatus === PhotTaskStatus.TASK_ACCOMPLISHED ? await engineManager.restartTask() : await engineManager.startTask()
                                            await engineManager.getTaskExceptionInformation()
                                            // await engineManager.resumeTask()
                                            proxy.$toast({
                                                value: '计算完成',
                                                type: 'success'
                                            })
                                        } else if (!graphManager.photGraph.graphId) {
                                            proxy.$toast({
                                                value: '请运行仿真工程',
                                                type: 'error'
                                            })
                                        } else {
                                            proxy.$toast({
                                                value: '请检查任务状态',
                                                type: 'error'
                                            })
                                            console.log('请检查任务状态')
                                        }
                                        proxy.$loading.close()
                                        proxy.$refs.MessageLogRef.concatLog()
                                    } catch (err) {
                                        proxy.$refs.MessageLogRef.concatLog(err)
                                        const errorLog = await mainManager.getServerLog('1000', 'phot_engine')
                                        console.log(errorLog)
                                        // proxy.$refs.MessageLogRef.concatLog(errorLog)
                                        proxy.$refs.MessageLogRef.concatLog(`【${graphManager.graphName}】 - 启动失败`)
                                        proxy.$loading.close()
                                        proxy.$toast({
                                            value: err,
                                            type: 'error'
                                        })
                                    }
                                    commandManager.executeCommand('test.engine.task.start')
                                }
                            },
                            {
                                display: 'column',
                                label: '暂停',
                                icon: 'pause',
                                id: '',
                                fn: async () => {
                                    if (!graphManager.photGraph) {
                                        return proxy.$toast({
                                            type: 'error',
                                            value: '未检测到工程'
                                        })
                                    }
                                    proxy.$loading.open()
                                    if (engineManager.taskStatus === PhotTaskStatus.TASK_RUNNING) {
                                        await engineManager.pauseTask(engineManager.taskId)
                                        proxy.$toast({
                                            value: '任务暂停',
                                            type: 'success'
                                        })
                                    } else {
                                        proxy.$toast({
                                            value: '请检查任务状态',
                                            type: 'error'
                                        })
                                        console.log('请检查任务状态')
                                    }
                                    proxy.$loading.close()
                                    commandManager.executeCommand('test.engine.task.pasue')
                                }
                            },
                        ]
                    },
                    {
                        display: 'column',
                        showText: true,
                        size: 'normal',
                        list: [
                            {
                            display: 'column',
                            label: '终止',
                            icon: 'a-zhongzhi',
                            id: '',
                            fn: async () => {
                                if (!graphManager.photGraph) {
                                    return proxy.$toast({
                                        type: 'error',
                                        value: '未检测到工程'
                                    })
                                }
                                proxy.$loading.open()
                                if (engineManager.taskStatus && Number(engineManager.taskStatus) !== PhotTaskStatus.TASK_CREATING) {
                                    await engineManager.cancelTask(engineManager.taskId)
                                    proxy.$toast({
                                        value: '任务终止',
                                        type: 'success'
                                    })
                                } else {
                                    proxy.$toast({
                                        value: '任务未启动',
                                        type: 'error'
                                    })
                                    console.log('任务未启动')
                                }
                                proxy.$loading.close()
                                commandManager.executeCommand('test.engine.task.stop')
                            }
                        },
                        {
                            display: 'column',
                            label: '任务管理',
                            icon: 'renwutiaodu',
                            id: '3',
                            fn: () => {
                                console.log('打开任务管理')
                                proxy.$refs.TaskManagementDialogRef.init()
                            }
                        },
                        ]
                    },
                ]
            },
            {
                title: '分析器',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '结果可视化',
                                icon: 'keshihua',
                                id: '',
                                fn: () => {
                                    openNewWindow()
                                    commandManager.executeCommand('PhotAnalyze.open')
                                }
                            },
                            {
                                display: 'column',
                                label: '新窗口',
                                icon: 'a-xinchuangkou1',
                                id: '',
                                fn: () => {
                                    commandManager.executeCommand('PhotAnalyze.newWindow')
                                }
                            },
                            {
                                display: 'column',
                                label: '关闭所有',
                                icon: 'a-guanbisuoyou1',
                                id: '',
                                fn: () => {
                                    commandManager.executeCommand('PhotAnalyze.closeAll')
                                }
                            },
                        ]
                    },
                ]
            },
            {
                title: '系统变量',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '系统变量设置',
                                icon: 'a-bianliang',
                                id: '',
                                fn: async () => {
                                    if (!graphManager.photGraph) {
                                        return proxy.$toast({
                                            type: 'error',
                                            value: '未检测到工程'
                                        })
                                    }
                                    await nextTick()
                                    environmentVariablesClickHandle()
                                    commandManager.executeCommand('system.variables')
                                }
                            }
                        ]
                    },
                ]
            },
        ],
        passiveDeviceToolbarList: [
            {
                title: '文件',
                type: 'file',
                options: [
                    {
                        display: 'row',
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '新建',
                                icon: 'xinjian',
                                id: '1',
                                fn: async () => {
                                    // try {
                                    //     proxy.$loading.open()
                                    //     await deviceManager.addGrid()
                                    //     proxy.$loading.close()
                                    //     proxy.$toast({
                                    //         value: '成功',
                                    //         type: 'success'
                                    //     })
                                    // } catch (error) {
                                    //     proxy.$loading.close()
                                    //     proxy.$toast({
                                    //         value: '系统错误，请稍后尝试',
                                    //         type: 'error'
                                    //     })
                                    // }
                                    proxy.$refs.NewPassiveDeviceDialogRef.init()
                                }
                            },
                        ]
                    },
                    {
                        display: 'row',
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '保存',
                                icon: 'baocun',
                                id: '2',
                                fn: async () => {
                                    console.log('保存')
                                    await deviceManager.saveGrid()
                                }
                            },
                        ]
                    },
                    {
                        display: 'column',
                        showText: true,
                        size: 'small',
                        list: [
                            {
                                display: 'row',
                                label: '打开',
                                icon: 'dakai',
                                id: '3',
                                fn: () => {
                                    folderBrowserClickHandle('open grid')
                                    commandManager.executeCommand('deviceManager.openGrid')
                                }
                            },
                            {
                                display: 'row',
                                label: '关闭',
                                icon: 'folder-close',
                                id: '4',
                                fn: async () => {
                                    if (!deviceManager.photGrid) {
                                        proxy.$toast({
                                            value: '未检测到正在运行的仿真工程',
                                            type: 'error'
                                        })
                                        return
                                    }
                                    proxy.$refs.ConfirmDialogRef.init()
                                    // await deviceManager.closeGrid()
                                }
                            },
                            {
                                display: 'row',
                                label: '退出',
                                icon: 'tuichu',
                                id: '5',
                                fn: () => {
                                    console.log('退出')
                                }
                            },
                        ]
                    }
                ]
            },
            {
                title: '仿真区域/通用设置',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        type: 'tool',
                        list: [
                            {
                                display: 'column',
                                label: '仿真区域设置',
                                icon: 'keshihua',
                                id: '3',
                                fn: () => {
                                    if (!deviceManager.photGrid) {
                                        return proxy.$toast({
                                            value: '未检测到工程',
                                            type: 'error'
                                        })
                                    }
                                    console.log('打开任务管理')
                                    proxy.$refs.EmulationAreaRef.init()
                                }
                            },
                        ]
                    },
                ]
            },
            {
                title: '波导设计',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '材料库',
                                icon: 'cailiaoku',
                                id: '1',
                                fn: async () => {
                                    // try {
                                    //     // commandManager.executeCommand('materialLibrary.open')
                                    proxy.$refs.MaterialManagerDialogRef.init()
                                    // } catch (error) {
                                    //     proxy.$toast({
                                    //         value: '系统错误，请稍后尝试',
                                    //         type: 'error'
                                    //     })
                                    //     proxy.$loading.close()
                                    // }
                                }

                            },
                            // {
                            //     display: 'column',
                            //     label: '新增材料',
                            //     icon: 'xinzengcailiao',
                            //     id: '2',
                            //     fn: () => {
                            //         // commandManager.executeCommand('materialLibrary.openAdd')
                            //         proxy.$refs.AddMaterialDialogRef.init()
                            //     }
                            // },
                        ]
                    },
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '波导',
                                icon: 'bodaoicon',
                                id: '2',
                                fn: () => {
                                    console.log('打开默认波导')
                                },
                                // 下拉选项波导类型列表
                                dataList: [
                                    {
                                        label: '矩形直波导',
                                        value: 'waveguide',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开矩形直波导')
                                            const source = {
                                                title: '矩形直波导',
                                                type: 'Waveguide',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'rectangle'
                                    },
                                    {
                                        label: 'S波导',
                                        value: 'sbend',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开S波导')
                                            const source = {
                                                title: 'S波导',
                                                type: 'Sbend',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'sbend'

                                    },
                                    {
                                        label: 'Y型波导',
                                        value: 'ysplitter',
                                        border: true,
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开Y型波导')
                                            const source = {
                                                title: 'Y型波导',
                                                type: 'Ysplitter',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'ySplitter'
                                    },
                                    {
                                        label: '方向耦合器',
                                        value: 'dc',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开方向耦合器')
                                            const source = {
                                                title: '方向耦合器',
                                                type: 'DirectionalCoupler',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'directional'
                                    },
                                    {
                                        label: '环形谐振腔',
                                        value: 'ring',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开环形谐振腔')
                                            const source = {
                                                title: '环形谐振腔',
                                                type: 'Ring',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'ring'
                                    },
                                    {
                                        label: '多模干涉耦合器',
                                        value: 'mmi',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开多模干涉耦合器')
                                            const source = {
                                                title: '多模干涉耦合器',
                                                type: 'Mmi',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'Mmi'
                                    },
                                    {
                                        label: '马赫曾德干涉仪',
                                        value: 'mzi',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开马赫曾德干涉仪')
                                            const source = {
                                                title: '马赫曾德干涉仪',
                                                type: 'Mzi',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'Mzi'
                                    },
                                    {
                                        label: '光纤',
                                        value: 'fiber',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开光纤')
                                            const source = {
                                                title: '光纤',
                                                type: 'Fiber',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'fiberWaveguide'
                                    },
                                    {
                                        label: '四分之一圆弧',
                                        value: 'arc',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开四分之一圆弧')
                                            const source = {
                                                title: '四分之一圆弧',
                                                type: 'Arc',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('wave', source)
                                        },
                                        // 可加入图标
                                        icon: 'arc'
                                    }
                                ]
                            },
                        ]
                    },
                ]
            },
            {
                title: 'FDTD仿真',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '光源',
                                icon: 'guangyuanicon',
                                id: '1',
                                fn: () => {
                                    console.log('打开默认光源')
                                },
                                // 下拉选项光源类型列表
                                dataList: [
                                    {
                                        label: '点光源',
                                        value: 'pointsource',
                                        fn: async () => {
                                            console.log('打开点光源')
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            const source = {
                                                title: '点光源',
                                                type: 'pointsource',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('light', source)
                                        },
                                        // 可加入点光源图标
                                        icon: 'pointsource'
                                    },
                                    {
                                        label: '线光源',
                                        value: 'linesource',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开线光源')
                                            const source = {
                                                title: '线光源',
                                                type: 'linesource',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('light', source)
                                        },
                                        // 可加入线光源图标
                                        icon: 'linesource'

                                    },
                                    {
                                        label: '面光源',
                                        value: 'planesource',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开面光源')
                                            const source = {
                                                title: '面光源',
                                                type: 'planesource',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('light', source)
                                        },
                                        // 可加入面光源图标
                                        icon: 'planesource'
                                    }
                                ]
                            },
                        ]
                    },
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '监视器',
                                icon: 'jianshiqiicon',
                                id: '3',
                                fn: () => {
                                    console.log('打开默认监视器')
                                },
                                // 下拉选项监视器类型列表
                                dataList: [
                                    {
                                        label: '线监视器',
                                        value: 'linedetector',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开线监视器')
                                            const source = {
                                                title: '线监视器',
                                                type: 'linedetector',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('detector', source)
                                        },
                                        // 可加入图标
                                        icon: 'jianshiqiicon'
                                    },
                                    {
                                        label: '矩形监视器',
                                        value: 'blockdetector',
                                        fn: () => {
                                            if (!deviceManager.photGrid) {
                                                return proxy.$toast({
                                                    value: '未检查到工程',
                                                    type: 'error'
                                                })
                                            }
                                            console.log('打开矩形监视器')
                                            const source = {
                                                title: '矩形监视器',
                                                type: 'blockdetector',
                                                show: false,
                                                list: []
                                            }
                                            proxy.$refs.DeviceContentRef.addSource('detector', source)
                                        },
                                        // 可加入图标
                                        icon: 'jianshiqiicon'
                                    },

                                ]

                            }
                        ]
                    },
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '运行',
                                icon: 'kaishi',
                                id: '1',
                                fn: async () => {
                                    if (!deviceManager.photGrid) {
                                        return proxy.$toast({
                                            value: '未检查到工程',
                                            type: 'error'
                                        })
                                    }
                                    console.log('运行')
                                    proxy.$loading.open('仿真任务进行中...')
                                    try {
                                        await deviceManager.run()
                                        const figures = await deviceManager.getFigures([-1,-1,-1])
                                        console.log('figures:', figures)
                                        deviceManager.figures.set(deviceManager.photGridId, figures)
                                        console.log('figuresMap:', deviceManager.figures.get(deviceManager.photGridId))
                                        const props = {
                                            figures,
                                            gridId: deviceManager.photGridId
                                        }
                                        proxy.$refs.CompoHistoryRef.addHistory(props, '2')
                                        proxy.$refs[`FiguresViewRef-${deviceManager.photGridId}`][0].init()
                                        proxy.$loading.close()
                                        proxy.$toast({
                                            value: '仿真任务完成',
                                            type: 'success'
                                        })
                                    } catch (err) {
                                        proxy.$loading.close()
                                        proxy.$toast({
                                            value: err,
                                            type: 'error'
                                        })
                                    }
                                }
                            },
                        ]
                    },
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '任务管理',
                                icon: 'renwutiaodu',
                                id: '3',
                                fn: () => {
                                    console.log('打开任务管理')
                                    proxy.$refs.TaskManagementDialogRef.init()
                                }
                            },
                        ]
                    },
                ]
            },
            {
                title: '模式分析',
                options: [
                    {
                        display: 'row',
                        showText: true,
                        size: 'large',
                        list: [
                            {
                                display: 'column',
                                label: '模式分析',
                                icon: 'keshihua',
                                id: '3',
                                fn: () => {
                                    console.log('打开任务管理')
                                    proxy.$refs.SchcemaParserDialogRef.init()
                                }
                            },
                        ]
                    },
                ]
            },
        ],
        activeDeviceToolbar: {
            default: [
                {
                    title: '文件',
                    type: 'file',
                    options: [
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '新建',
                                    icon: 'xinjian',
                                    id: '',
                                    arrow: true,
                                    fn: async () => {
                                        await nextTick()
                                        proxy.$refs.NewActiveDeviceDialogRef.init()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '保存',
                                    icon: 'baocun',
                                    id: '',
                                    arrow: true,
                                    fn: async () => {
                                        await graphManager.saveGraph()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'column',
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '打开',
                                    icon: 'dakai',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        folderBrowserClickHandle('open graph')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '关闭',
                                    icon: 'folder-close',
                                    id: '',
                                    fn: async () => {
                                        await graphManager.saveGraph()
                                        await graphManager.closeGraph(graphManager.photGraph.uid, graphManager.photGraph.graphId)
                                        await nextTick()
    
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '退出',
                                    icon: 'tuichu',
                                    id: '',
                                    fn: () => commandManager.executeCommand('file.quit')
                                },
                            ]
                        },
                        {
                            display: 'column',
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '打印',
                                    icon: 'dayin',
                                    id: '',
                                    fn: () => commandManager.executeCommand('main.file.print')
                                },
                                {
                                    display: 'row',
                                    label: '帮助',
                                    icon: 'help',
                                    id: '',
                                    arrow: true,
                                    fn: () => commandManager.executeCommand('main.file.help')
                                },
                                {
                                    display: 'row',
                                    label: '设置',
                                    icon: 'shezhi',
                                    id: '',
                                    fn: () => {
                                        settingClickHandle()
                                        commandManager.executeCommand('main.file.setting')
                                    }
                                },
                            ]
                        },
                    ]
                },
            ],
            opticalFiber: [
                {
                    title: '文件',
                    type: 'file',
                    options: [
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '新建',
                                    icon: 'xinjian',
                                    id: '',
                                    arrow: true,
                                    fn: async () => {
                                        await nextTick()
                                        proxy.$refs.NewActiveDeviceDialogRef.init()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '保存',
                                    icon: 'baocun',
                                    id: '',
                                    arrow: true,
                                    fn: async () => {
                                        await graphManager.saveGraph()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'column',
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '打开',
                                    icon: 'dakai',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        folderBrowserClickHandle('open graph')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '关闭',
                                    icon: 'folder-close',
                                    id: '',
                                    fn: async () => {
                                        await graphManager.saveGraph()
                                        await graphManager.closeGraph(graphManager.photGraph.uid, graphManager.photGraph.graphId)
                                        await nextTick()
    
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '退出',
                                    icon: 'tuichu',
                                    id: '',
                                    fn: () => commandManager.executeCommand('file.quit')
                                },
                            ]
                        },
                        {
                            display: 'column',
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '打印',
                                    icon: 'dayin',
                                    id: '',
                                    fn: () => commandManager.executeCommand('main.file.print')
                                },
                                {
                                    display: 'row',
                                    label: '帮助',
                                    icon: 'help',
                                    id: '',
                                    arrow: true,
                                    fn: () => commandManager.executeCommand('main.file.help')
                                },
                                {
                                    display: 'row',
                                    label: '设置',
                                    icon: 'shezhi',
                                    id: '',
                                    fn: () => {
                                        settingClickHandle()
                                        commandManager.executeCommand('main.file.setting')
                                    }
                                },
                            ]
                        },
                    ]
                },
                {
                    title: '剪切板',
                    type: 'clipboard',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '粘贴',
                                    icon: 'niantie',
                                    id: '',
                                    // arrow: true,
                                    fn: () => commandManager.executeCommand('main.clipboard.stickup')
                                }
                            ]
                        },
                        {
                            display: 'column',
                            showText: true,
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '复制',
                                    icon: 'fuzhi',
                                    id: '',
                                    fn: () => commandManager.executeCommand('main.clipboard.copy')
                                },
                                {
                                    display: 'row',
                                    label: '剪切',
                                    icon: 'cut',
                                    id: '',
                                    fn: () => commandManager.executeCommand('main.clipboard.cut')
                                },
                                {
                                    display: 'row',
                                    label: '删除',
                                    icon: 'shanchu',
                                    id: '',
                                    fn: () => commandManager.executeCommand('main.clipboard.clean')
                                },
                            ]
                        },
                    ]
                },
                {
                    title: '文本编辑',
                    type: 'text-mode',
                    options: [
                        {
                            display: 'column',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '添加文本',
                                    icon: 'add-text',
                                    id: '7',
                                    fn: () => {
                                      console.log('添加文本')
                                    }
                                }
                            ]
                        },
                        {
                            display: 'row',
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '字体',
                                    icon: '',
                                    id: '8-1',
                                    fn: () => {
                                      console.log('字体')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '大小',
                                    icon: '',
                                    id: '8-2',
                                    fn: () => {
                                      console.log('大小')
                                    }
                                },
                            ]
                        },
                        {
                            display: 'row',
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '',
                                    icon: 'text-left',
                                    id: '9-1',
                                    fn: () => {
                                      console.log('text-left')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '',
                                    icon: 'text-center',
                                    id: '9-2',
                                    fn: () => {
                                      console.log('text-center')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '',
                                    icon: 'text-right',
                                    id: '9-3',
                                    fn: () => {
                                      console.log('text-right')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '',
                                    icon: 'text-background-color',
                                    id: '9-4',
                                    fn: () => {
                                      console.log('text-background-color')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '',
                                    icon: 'text-color',
                                    id: '9-5',
                                    fn: () => {
                                      console.log('text-color')
                                    }
                                },
                            ]
                        },
                    ]
                },
                {
                    title: '组件编辑',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '编辑参数',
                                    icon: 'a-bianzhicanshu',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        commandManager.executeCommand('main.editor.edit')
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '在PhotCode打开',
                                    icon: 'a-zaiPhotCodedakai',
                                    id: '',
                                    fn: () => {
                                        cmdFn('D://code/mlyGitLibrary/phot-client')
                                        commandManager.executeCommand('main.editor.openInCode')
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '启动PhotCode',
                                    icon: 'a-qidongPhotCode',
                                    id: '',
                                    fn: () => {
                                        cmdFn()
                                        commandManager.executeCommand('main.editor.startCode')
                                    }
                                },
                            ]
                        },
                    ]
                },
                {
                    title: '仿真',
                    options: [
                        {
                            display: 'column',
                            showText: true,
                            size: 'normal',
                            list: [
                                {
                                    display: 'column',
                                    label: '运行',
                                    icon: 'kaishi',
                                    id: '',
                                    fn: async () => {
                                        commandManager.executeCommand('test.engine.task.start')
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '暂停',
                                    icon: 'pause',
                                    id: '',
                                    fn: async () => {
                                        commandManager.executeCommand('test.engine.task.pasue')
                                    }
                                },
                            ]
                        },
                        {
                            display: 'column',
                            showText: true,
                            size: 'normal',
                            list: [
                                {
                                display: 'column',
                                label: '终止',
                                icon: 'a-zhongzhi',
                                id: '',
                                fn: async () => {
                                    commandManager.executeCommand('test.engine.task.stop')
                                }
                            },
                            {
                                display: 'column',
                                label: '任务管理',
                                icon: 'renwutiaodu',
                                id: '3',
                                fn: () => {
                                    proxy.$refs.TaskManagementDialogRef.init()
                                }
                            },
                            ]
                        },
                    ]
                },
                {
                    title: '分析器',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '结果可视化',
                                    icon: 'keshihua',
                                    id: '',
                                    fn: () => {
                                        openNewWindow()
                                        commandManager.executeCommand('PhotAnalyze.open')
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '新窗口',
                                    icon: 'a-xinchuangkou1',
                                    id: '',
                                    fn: () => {
                                        commandManager.executeCommand('PhotAnalyze.newWindow')
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '关闭所有',
                                    icon: 'a-guanbisuoyou1',
                                    id: '',
                                    fn: () => {
                                        commandManager.executeCommand('PhotAnalyze.closeAll')
                                    }
                                },
                            ]
                        },
                    ]
                },
                {
                    // TODO: phot-ui create block-type = simulation-mode
                    title: '模拟区域',
                    // type: 'simulation-mode',
                    type: 'input',
                    options: [
                        {
                            display: 'column',
                            showText: true,
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '仿真步数',
                                    labelWidth: '60px',
                                    icon: '',
                                    id: '',
                                    prop: 'permeability',
                                    value: 1.55,
                                    // value: 1.0,
                                    type: 'text',
                                    precision: 3,
                                    step: 0.001,
                                    min: 0,
                                    onInput: async ($event: any, prop: any) => {
                                    }
                                },
                            ]
                        },
                        {
                            display: 'column',
                            showText: true,
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    type: 'switch',
                                    size: 'small',
                                    btnList: [
                                      {
                                        prop: 'switch1',
                                        value: false,
                                        onChange: (e: any) => {
                                          console.log(e)
                                        }
                                      },
                                    ]
                                },
                            ]
                        },
                    ]
                }
            ],
            electroOptical: [
                {
                    title: '文件',
                    type: 'file',
                    options: [
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '新建',
                                    icon: 'xinjian',
                                    id: '1',
                                    fn: async () => {
                                        proxy.$refs.NewActiveDeviceDialogRef.init()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '保存',
                                    icon: 'baocun',
                                    id: '2',
                                    fn: async () => {
                                        console.log('保存')
                                        await deviceManager.saveGrid()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'column',
                            showText: true,
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '打开',
                                    icon: 'dakai',
                                    id: '3',
                                    fn: () => {
                                        commandManager.executeCommand('')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '关闭',
                                    icon: 'folder-close',
                                    id: '4',
                                    fn: async () => {
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '退出',
                                    icon: 'tuichu',
                                    id: '5',
                                    fn: () => {
                                        console.log('退出')
                                    }
                                },
                            ]
                        }
                    ]
                },
                {
                    title: '材料库管理',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '材料库',
                                    icon: 'cailiaoku',
                                    id: '1',
                                    fn: async () => {
                                    }
    
                                },
                                {
                                    display: 'column',
                                    label: '新增材料',
                                    icon: 'xinzengcailiao',
                                    id: '2',
                                    fn: () => {
                                    }
                                },
                            ]
                        }
                    ]
                },
                {
                    title: '仿真',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '运行',
                                    icon: 'kaishi',
                                    id: '1',
                                    fn: async () => {
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '结果可视化',
                                    icon: 'keshihua',
                                    id: '',
                                    fn: () => {
                                        openNewWindow()
                                        commandManager.executeCommand('PhotAnalyze.open')
                                    }
                                },
                            ]
                        },
                    ]
                },
            ],
            semiconductor: [
                {
                    title: '文件',
                    type: 'file',
                    options: [
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '新建',
                                    icon: 'xinjian',
                                    id: '1',
                                    fn: async () => {
                                        proxy.$refs.NewActiveDeviceDialogRef.init()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'row',
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '保存',
                                    icon: 'baocun',
                                    id: '2',
                                    fn: async () => {
                                        console.log('保存')
                                        await deviceManager.saveGrid()
                                    }
                                },
                            ]
                        },
                        {
                            display: 'column',
                            showText: true,
                            size: 'small',
                            list: [
                                {
                                    display: 'row',
                                    label: '打开',
                                    icon: 'dakai',
                                    id: '3',
                                    fn: () => {
                                        folderBrowserClickHandle('open grid')
                                        commandManager.executeCommand('deviceManager.openGrid')
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '关闭',
                                    icon: 'folder-close',
                                    id: '4',
                                    fn: async () => {
                                        proxy.$refs.ConfirmDialogRef.init()
                                        // await deviceManager.closeGrid()
                                    }
                                },
                                {
                                    display: 'row',
                                    label: '退出',
                                    icon: 'tuichu',
                                    id: '5',
                                    fn: () => {
                                        console.log('退出')
                                    }
                                },
                            ]
                        }
                    ]
                },
                {
                    title: '材料库管理',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '材料库',
                                    icon: 'cailiaoku',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        proxy.$refs.MaterialLibraryDialogRef.init()
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '自定义材料',
                                    icon: 'xinzengcailiao',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        proxy.$refs.MaterialCustomDialogRef.init()
                                    }
                                }
                            ]
                        },
                    ]
                },
                {
                    title: '横向结构',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    icon: 'horizontal-design',
                                    id: '1',
                                    label: '横向结构设计',
                                    // 下拉选项光源类型列表
                                    dataList: [
                                        {
                                            label: '横截面行列设计',
                                            value: 'plane',
                                            fn: async () => {
                                                console.log('横截面行列设计')
                                                proxy.$refs.StructureDesignRef.init('横向结构设计-横截面设计', 'plane')
                                            }
                                        },
                                        {
                                            label: '电极',
                                            value: 'electrode',
                                            fn: async () => {
                                                console.log('电极')
                                                proxy.$refs.StructureDesignRef.init('横向结构设计-电极', 'electrode')
                                            }
                                        },
                                        {
                                            label: '绝缘层',
                                            value: 'insulation',
                                            fn: async () => {
                                                console.log('绝缘层')
                                                proxy.$refs.StructureDesignRef.init('横向结构设计-绝缘层', 'insulation')
                                            }
                                        },
                                        {
                                            label: '有源区设计',
                                            value: 'active',
                                            fn: async () => {
                                                console.log('有源区设计')
                                                proxy.$refs.StructureDesignRef.init('横向结构设计-有源区设计', 'active')
                                            }
                                        },
                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    title: '纵向结构',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    icon: 'vertical-design',
                                    label: '纵向结构设计',
                                    id: '',
                                    fn: async () => {
                                        console.log('纵向结构设计')
                                        proxy.$refs.QuantumWellDeviceRef.StructureDesignRef.init('纵向结构设计', 'column', '1')
                                    }
                                },
                            ]
                        },
                    ]
                },
                {
                    title: '视图',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '横向全屏',
                                    icon: 'horizontal-fullscreen',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        commandManager.executeCommand('system.variables')
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '纵向全屏',
                                    icon: 'vertical-fullscreen',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        commandManager.executeCommand('system.variables')
                                    }
                                }
                            ]
                        },
                    ]
                },
                {
                    title: '仿真',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '运行',
                                    icon: 'kaishi',
                                    id: '1',
                                    fn: async () => {
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '任务管理',
                                    icon: 'task-manage',
                                    id: '3',
                                    fn: () => {
                                        console.log('打开任务管理')
                                        proxy.$refs.TaskManagementDialogRef.init()
                                    }
                                },
                            ]
                        },
                    ]
                },
                {
                    title: '系统环境变量',
                    options: [
                        {
                            display: 'row',
                            showText: true,
                            size: 'large',
                            list: [
                                {
                                    display: 'column',
                                    label: '输入信号',
                                    icon: 'input-signal',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        proxy.$refs.InputSignalDialogRef.init()
                                    }
                                },
                                {
                                    display: 'column',
                                    label: '光学参数',
                                    icon: 'optical-parameter',
                                    id: '',
                                    fn: async () => {
                                        await nextTick()
                                        proxy.$refs.OpticalParameterDialogRef.init()
                                    }
                                }
                            ]
                        },
                    ]
                },
            ],
        }
        

    }) as any
    const newFileClickHandle = () => {  // 新建
        proxy.$refs.NewFileDialogRef.init()
    }
    // const newProjectClickHandle = () => {   // 新建仿真工程
    //     proxy.$refs.NewProjectDialogRef.init()
    // }
    const newGraphClickHandle = () => {   // 新建仿真工程
        proxy.$refs.NewGraphDialogRef.init()
    }
    const refreshProjectClickHandle = () => {
    }
    const openFileClickHandle = () => {     // 打开仿真工程
        proxy.$refs.OpenFileDialogRef.init()
    }
    const deleteFileClickHandle = () => {   // 删除文件/文件夹
        proxy.$refs.DeleteProjectDialogRef.init()
    }
    const folderBrowserClickHandle = (type?: any) => {    // 打开文件浏览器
        proxy.$refs.FolderBrowserDialogRef.init(type)
    }
    const importProjectClickHandle = () => {    // 导入
        proxy.$refs.ImportProjectDialogRef.init()
    }
    const parameterEditorClickHandle = () => {  // 仿真工程-参数设置
        proxy.$refs.ParameterEditorRef.init()
    }
    const environmentVariablesClickHandle = async () => { // 仿真工程-系统变量
        proxy.$refs.EnvironmentVariablesRef.init()
    }
    const settingClickHandle = () => { // 仿真工程-系统变量
        proxy.$refs.SettingRef.init()
    }
    const getDirectoryList = async (drectoryPath: string = './') => {
        return await project.openDirectory(drectoryPath)
    }
    const closeCurrentGraph = () => {
        
    }
    const saveGraph = async (graphName: string) => {    // 保存计算图
        await graph.saveGraph(graphName).then((res: any) => {
            console.log(res)
        }).catch((err: any) => {
            console.log(err)
        })
    }
    const calculateTask = async (taskId: string) =>  {  // 运行
        await engine.calculateTask(taskId).then((res: any) => {
            console.log(res)
        }).catch((err: any) => {
            console.log(err)
        })
    }
    const cancelTask = async (taskId: string) =>  { // 终止
        await engine.cancelTask(taskId).then((res: any) => {
            console.log(res)
        }).catch((err: any) => {
            console.log(err)
        })
    }
    const deleteTask = async (taskId: string) =>  { // 删除任务
        await engine.deleteTask(taskId).then((res: any) => {
            console.log(res)
        }).catch((err: any) => {
            console.log(err)
        })
    }
    const addTask = async (photGraph: any, taskId: string, priority: number, executionTime: number) => {
        await engine.addTask(photGraph, taskId, priority, executionTime)
    }
    const onScreenfullClickHandle = () => {
        const el: any = document.getElementById('workspace')
        if (screenfull.isEnabled) {
            screenfull.request(el)
        }
    }
    const openNewWindow = () => {
        ipcRenderer.send('control', 'new-win', 'PhotAnalyze')
    }
    const closeAllSubWindow = () => {
        ipcRenderer.send('child-data', 'close', 'PhotAnalyze')
    }
    const cmdFn = (path: string = '') => {
        let cmdStr = 'code ' + path
        let workerProcess = exec(cmdStr)
        // 打印正常的后台可执行程序输出
        workerProcess.stdout.on('data', function (data: any) {
            console.log('stdout: ' + data)
        })
        // 打印错误的后台可执行程序输出
        workerProcess.stderr.on('data', function (data: any) {
            console.log('stderr: ' + data)
        })
        // 退出之后的输出
        workerProcess.on('close', function (code: any) {
            console.log('out code：' + code)
        })
    }
    const gridData = reactive({
        gridXlength: 100,
        gridYlength: 200,
        gridZlength: 50,
        pmlWidthX: 1.0,
        pmlWidthY: 1.0,
        pmlWidthZ: 1.0,
        gridSpacing: 0.01,
        envN: 1.0,
        permittivity: 1.0,
        permeability: 1.0,
    })
    const onInputHandle = (e: any) => {

    }
    const updateGrid = async () => {
        proxy.$loading.open('正在更新仿真工程...')
        try {
            await deviceManager.updateGrid(deviceManager.photGrid)
            let axisIndex = deviceManager.taskStatus.get(deviceManager.photGridId) === 2 ? [-1,-1,-1] : [0,0,0]
            const figures = await deviceManager.getFigures(axisIndex)
            deviceManager.figures.set(deviceManager.photGridId, figures)
			temporaryData.photGrid = deepClone(deviceManager.photGrid)
            proxy.$refs[`FiguresViewRef-${deviceManager.photGridId}`][0].init()
            proxy.$loading.close()
            proxy.$toast({
                type: 'success',
                value: '更新成功'
            })
        } catch (err: any) {
            proxy.$loading.close()
            proxy.$toast({
                type: 'error',
                value: '更新失败'
            })
        }
    }
    const resetPhotGrid = () => {
        hooksData.passiveDeviceToolbarList[1].options.map((option: any) => {
            option.list.map((item: any) => {
                item.readonly = false
                item.value = deviceManager.photGrid[item.prop]
            })
        })
    }

    return {
        temporaryData,
        hooksData,
        newFileClickHandle,
        openFileClickHandle,
        deleteFileClickHandle,
        folderBrowserClickHandle,
        importProjectClickHandle,
        saveGraph,
        cmdFn,
        gridData,
        onInputHandle,
        updateGrid
    }
}
export default useHooks